{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "'''\n",
    "【课程2.1】  数据类型概述\n",
    "\n",
    "Python标准数据类型：Numbers数字，String字符串，List列表，Tuple元祖，Dict字典\n",
    "\n",
    "'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'int'> <class 'float'>\n"
     ]
    }
   ],
   "source": [
    "# Numbers数字分为：int整型，long长整型，float浮点型，complex复数\n",
    "\n",
    "x1 = 10\n",
    "x2 = 10.0\n",
    "print(type(x1),type(x2))\n",
    "\n",
    "# print()函数，用于输出/打印内容\n",
    "# type()函数，用于查看数据类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world! <class 'str'>\n",
      "hehe\n",
      "hahaha\n",
      "what is this?\n",
      "it`s a cat.\n"
     ]
    }
   ],
   "source": [
    "# String字符串由数字、字母、下划线组成的一串字符，用于表示文本的数据类型\n",
    "\n",
    "x3 = \"hello world!\"\n",
    "print(x3,type(x3))\n",
    "print('hehe')\n",
    "print(\"hahaha\")\n",
    "print('''what is this?\n",
    "it`s a cat.''')\n",
    "# 一定用英文标点符号，单引号('') 双引号(\"\")一样，三引号(''''''或\"\"\"\"\"\")可以表示多行字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True <class 'bool'>\n",
      "True\n",
      "True\n",
      "10\n"
     ]
    }
   ],
   "source": [
    "# bool布尔型：True，False，用于做判断\n",
    "\n",
    "x4 = True\n",
    "print(x4,type(x4))\n",
    "\n",
    "print(True == 1)\n",
    "print(False == 0)\n",
    "print(True * 10)\n",
    "# True实际值是1，False实际值是0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 'a', 2.4, 502.2, [1, 2, 3]] <class 'list'>\n"
     ]
    }
   ],
   "source": [
    "# List列表，支持字符，数字，字符串以包含列表（即嵌套），用[]标识，有序对象\n",
    "\n",
    "x5 = [1,'a',2.4,502.2,[1,2,3]]\n",
    "print(x5,type(x5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1, 2, 3, 'hello') <class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "# Tuple元祖，用（）标识，不能二次赋值，可以理解成不可变的列表（只读列表），有序对象\n",
    "\n",
    "x6 = (1,2,3,'hello')\n",
    "print(x6,type(x6))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'tel': 10001000, 'city': 'shanghai', 'name': 'fatbird'} <class 'dict'>\n"
     ]
    }
   ],
   "source": [
    "# Dict字典，用{}标识，由索引(key)和它对应的值value组成，无序对象\n",
    "\n",
    "x7 = {\"name\":\"fatbird\", \"city\":\"shanghai\", \"tel\":10001000}\n",
    "print(x7,type(x7))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10.8 <class 'float'>\n",
      "10 <class 'int'>\n",
      "----------\n",
      "10 <class 'int'>\n",
      "10.0 <class 'float'>\n",
      "----------\n",
      "10.0 <class 'float'>\n",
      "10.0 <class 'str'>\n",
      "10.0 <class 'float'>\n",
      "----------\n"
     ]
    }
   ],
   "source": [
    "# 数据类型转换方法  **这里暂时只针对int，float，str三者，list/tuple/dict后面课程讲\n",
    "\n",
    "var1 = 10.8\n",
    "var2 = int(var1)\n",
    "print(var1,type(var1))\n",
    "print(var2,type(var2))\n",
    "print('----------')\n",
    "# int(x)函数：将x转为整数，如果是四舍五入则是round(x)函数\n",
    "\n",
    "var1 = 10\n",
    "var2 = float(var1)\n",
    "print(var1,type(var1))\n",
    "print(var2,type(var2))\n",
    "print('----------')\n",
    "# float(x)函数：将x转为浮点数\n",
    "\n",
    "var1 = 10.0\n",
    "var2 = str(var1)\n",
    "var3 = float(var2)\n",
    "print(var1,type(var1))\n",
    "print(var2,type(var2))\n",
    "print(var3,type(var3))\n",
    "print('----------')\n",
    "# str(x)函数：将x转为字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "'''\n",
    "【课程2.2】  认识变量\n",
    "\n",
    "什么是变量？ —— 方程式“=”左边的，就是变量\n",
    "1、给变量赋值即创建该变量，并且同时赋予该变量\n",
    "① 变量名\n",
    "② 变量类型\n",
    "等号（=）用来给变量赋值\n",
    "\n",
    "2、变量命名规则：\n",
    "① 变量名第一个字符必须是字母（大小写均可）或者下划线（“_”），不能数字开头；\n",
    "② 变量名不能和常用功能性名字重合，例如print，if，for\n",
    "③ 不要有空格\n",
    "\n",
    "'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "100\n",
      "1000.0\n",
      "John\n"
     ]
    }
   ],
   "source": [
    "# 变量赋值\n",
    "\n",
    "counter = 100 # 赋值整型变量\n",
    "miles = 1000.0 # 浮点型\n",
    "name = \"John\" # 字符串\n",
    " \n",
    "print(counter)\n",
    "print(miles)\n",
    "print(name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 1 1 1 2 hello\n"
     ]
    }
   ],
   "source": [
    "# 多变量赋值\n",
    "\n",
    "a = b = c = 1\n",
    "d , e , f = 1 , 2 , 'hello'\n",
    "print(a,b,c,d,e,f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n",
      "20\n"
     ]
    }
   ],
   "source": [
    "# 动态变量 → 变量的值是可更改的，或者说，变量可以随时指向任意值\n",
    "\n",
    "var1 = 10\n",
    "print(var1)\n",
    "var1 = 20\n",
    "print(var1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "'''\n",
    "【课程2.3】  运算符\n",
    "\n",
    "什么是运算符？\n",
    "1 +2 = 3 的例子中，1 和 2 被称为操作数，\"+\" 称为运算符\n",
    "'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a加b 的值为： 31\n",
      "a减b 的值为： 11\n",
      "a乘b 的值为： 210\n",
      "a除b 的值为： 2.1\n",
      "a取b的模为： 1\n",
      "2的3次方的值为： 8\n",
      "10除4的整除数为： 2\n"
     ]
    }
   ],
   "source": [
    "# 算数运算符\n",
    "\n",
    "a, b, c = 21, 10, 0\n",
    " \n",
    "c = a + b  # 加法\n",
    "print (\"a加b 的值为：\", c)\n",
    " \n",
    "c = a - b  # 减法\n",
    "print( \"a减b 的值为：\", c )\n",
    " \n",
    "c = a * b  # 乘法\n",
    "print( \"a乘b 的值为：\", c )\n",
    " \n",
    "c = a / b  # 除法\n",
    "print( \"a除b 的值为：\", c )\n",
    " \n",
    "c = a % b  # 取模，返回除法的余数\n",
    "print( \"a取b的模为：\", c)\n",
    " \n",
    "# 修改变量 a 、b 、c\n",
    "a, b, = 2, 3\n",
    "c = a**b   # 幂\n",
    "print( \"2的3次方的值为：\", c)\n",
    " \n",
    "a, b = 10, 4\n",
    "c = a//b  # 取整除数 \n",
    "print( \"10除4的整除数为：\", c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "True\n",
      "True\n",
      "False\n",
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "# 比较运算符\n",
    "\n",
    "a, b = 21, 10\n",
    "print(a == b)  # 等于\n",
    "print(a != b)  # 不等于\n",
    "print(a > b)  # 大于\n",
    "print(a < b)  # 小于\n",
    "print(a >= 21)  # 大于等于\n",
    "print(a <= 2)  # 小于等于"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "True\n",
      "False\n",
      "-----\n",
      "True\n",
      "-----\n",
      "False True True True False\n"
     ]
    }
   ],
   "source": [
    "# 逻辑运算符\n",
    "\n",
    "print(True and False)  # and：且\n",
    "print(True or False)  # or：或\n",
    "print(not True)  # not：非\n",
    "print('-----')\n",
    "\n",
    "# 布尔型的本质：True的值等于1，False的值等于0\n",
    "print(True>0)\n",
    "print('-----')\n",
    "\n",
    "print(bool(0),bool(3),bool(-1),bool([1,2,3]),bool(0))\n",
    "# bool()函数：将值转换为布尔型，其中只有以下情况bool()返回False：0, 0.0, None，'', [] , {}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "# 成员运算符\n",
    "\n",
    "lst = [1,2,3,4,5,6]\n",
    "a,b = 1,10\n",
    "print(a in lst)  # a 在 lst 序列中 , 如果 x 在 y 序列中返回 True。\n",
    "print(b not in lst)  # b 不在 lst 序列中 , 如果 x 不在 y 序列中返回 True。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "'''\n",
    "【课程2.4】  注释#\n",
    "\n",
    "注释是用来说明代码\n",
    "程序运行的时候，Python解释器会直接忽略掉注释 → 有没有注释不影响程序的执行结果，但是影响到别人能不能看懂你的代码。\n",
    "但“#”不只代表注释,还代表某些文件的特殊格式，写在脚本开头\n",
    "注意：注释只在脚本中起作用\n",
    "\n",
    "'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world!\n"
     ]
    }
   ],
   "source": [
    "print('hello world!')\n",
    "# print('I love python')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "a = [1,2,3,4]\n",
    "#a = {'name':'fatbird', 'city':'shanghai', 'tel':10001000}\n",
    "for i in a:\n",
    "    print(i)\n",
    "\n",
    "# 注释也可以用于标记暂不运行语句"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
